home *** CD-ROM | disk | FTP | other *** search
- Path: diku.dk!null
- From: null@diku.dk (Niels Ull Jacobsen)
- Newsgroups: comp.lang.c++
- Subject: Re: Fastest way to index thru an array????
- Date: 14 Jan 1996 13:38:04 GMT
- Organization: Department of Computer Science, U of Copenhagen
- Sender: null@tyr.diku.dk
- Message-ID: <4db0vs$6fe@odin.diku.dk>
- References: <4d1g3k$o09@solaris.cc.vt.edu>
- NNTP-Posting-Host: odin.diku.dk
- X-Newsreader: NN version 6.5.0 #13
-
- Ashutosh Gokhale <ashutosh> writes:
-
- >Suppose I have an array A[][][] which I declare as
- > double ***A and then assign memory to it using new operator.
- >Now consider that A has dimensions A[50][60][70]. Then I can index thru ALL
- >entries of A using
- >for(i=1; i<50; i++)
- > {
- > for(j=1; j<60; j++)
- > {
- > for(k=1; k<70; k++)
- > {
- > A[i][j][k] = <some expression>;
- > }
- > }
- > }
- All the counters should start at 0.
- >But the above way is surely the most time-INEFFICIENT way.
- >Can someone suggest me the MOST time efficient way of indexing through A[][][]?
-
- What you have described is, given any decent compiler, the most
- efficient method as the problem is formulated.
-
- The only real improvement you could make was if you could control the
- allocation of A to make sure that the rows were laid out in order.
- That is, declaring A as:
- double * A[50][60];
-
- pMem = new double[50*60*70];
- for(i=0; i<50;i++)
- for(j=0;j<60;j++)
- A[i][j] = &(pMem[(i*60*+j)*70]);
-
- In that case you could loop through A with a simple
-
- for(k=0; k<50*60*70; k++)
- A[0][0][k] = <some expression>;
-
-
- >Thanks a lot
-
- --
- Niels Ull Jacobsen, Dep. of CS, U of Copenhagen (null@diku.dk)
- Roenne Alle 3 st.th, 2860 Soeborg, Denmark, tel. +45 39 66 39 86
-
-